package cn.iocoder.yudao.module.vote.controller.admin.voteuserinfodetail;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.vote.controller.admin.voteuserinfodetail.vo.*;
import cn.iocoder.yudao.module.vote.dal.dataobject.voteuserinfodetail.VoteUserInfoDetailDO;
import cn.iocoder.yudao.module.vote.convert.voteuserinfodetail.VoteUserInfoDetailConvert;
import cn.iocoder.yudao.module.vote.service.voteuserinfodetail.VoteUserInfoDetailService;

@Api(tags = "管理后台 - 用户信息详情")
@RestController
@RequestMapping("/vote/user-info-detail")
@Validated
public class VoteUserInfoDetailController {

    @Resource
    private VoteUserInfoDetailService userInfoDetailService;

    @PostMapping("/create")
    @ApiOperation("创建用户信息详情")
    @PreAuthorize("@ss.hasPermission('vote:user-info-detail:create')")
    public CommonResult<Long> createUserInfoDetail(@Valid @RequestBody VoteUserInfoDetailCreateReqVO createReqVO) {
        return success(userInfoDetailService.createUserInfoDetail(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新用户信息详情")
    @PreAuthorize("@ss.hasPermission('vote:user-info-detail:update')")
    public CommonResult<Boolean> updateUserInfoDetail(@Valid @RequestBody VoteUserInfoDetailUpdateReqVO updateReqVO) {
        userInfoDetailService.updateUserInfoDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除用户信息详情")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('vote:user-info-detail:delete')")
    public CommonResult<Boolean> deleteUserInfoDetail(@RequestParam("id") Long id) {
        userInfoDetailService.deleteUserInfoDetail(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得用户信息详情")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('vote:user-info-detail:query')")
    public CommonResult<VoteUserInfoDetailRespVO> getUserInfoDetail(@RequestParam("id") Long id) {
        VoteUserInfoDetailDO userInfoDetail = userInfoDetailService.getUserInfoDetail(id);
        return success(VoteUserInfoDetailConvert.INSTANCE.convert(userInfoDetail));
    }

    @GetMapping("/list")
    @ApiOperation("获得用户信息详情列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('vote:user-info-detail:query')")
    public CommonResult<List<VoteUserInfoDetailRespVO>> getUserInfoDetailList(@RequestParam("ids") Collection<Long> ids) {
        List<VoteUserInfoDetailDO> list = userInfoDetailService.getUserInfoDetailList(ids);
        return success(VoteUserInfoDetailConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得用户信息详情分页")
    @PreAuthorize("@ss.hasPermission('vote:user-info-detail:query')")
    public CommonResult<PageResult<VoteUserInfoDetailRespVO>> getUserInfoDetailPage(@Valid VoteUserInfoDetailPageReqVO pageVO) {
        PageResult<VoteUserInfoDetailDO> pageResult = userInfoDetailService.getUserInfoDetailPage(pageVO);
        return success(VoteUserInfoDetailConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出用户信息详情 Excel")
    @PreAuthorize("@ss.hasPermission('vote:user-info-detail:export')")
    @OperateLog(type = EXPORT)
    public void exportUserInfoDetailExcel(@Valid VoteUserInfoDetailExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<VoteUserInfoDetailDO> list = userInfoDetailService.getUserInfoDetailList(exportReqVO);
        // 导出 Excel
        List<VoteUserInfoDetailExcelVO> datas = VoteUserInfoDetailConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "用户信息详情.xls", "数据", VoteUserInfoDetailExcelVO.class, datas);
    }

}
